<?php
namespace Admin\Form;

use Zend\InputFilter;
use Zend\Form\Form;
use Zend\Form\Element;
use Zend\Db\Adapter\AdapterInterface;

class SliderForm extends Form
{
	protected $dbAdapter;
    public function __construct(AdapterInterface $dbAdapter)
    {
		$this->setDbAdapter($dbAdapter);
        // we want to ignore the name passed
        parent::__construct('slider');

        $this->setAttribute('method', 'post');
        $this->add(array(
            'name' => 'id',
            'attributes' => array(
                'type'  => 'hidden',
            ),
        ));

      $this->add(array(
			'type'  => 'radio',
			'name'  => 'trangthai',
			'options' => array(
				'value_options' => array(
					'1' => array(
						'label' => 'Hiển thị',
						'value' => 'Hiển thị',
						'selected' => 'selected',
						'attributes' => array(
							'data-item' => '1',
						),
					),
					'0' => array(
						'label' => 'Ẩn',
						'value' => 'Ẩn',
						'attributes' => array(
							'data-item' => '0',
						),
					),
				),
				
			),
		));

        
		
		$this->addElements();
		$this->addElements2();
       
        $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                'type'  => 'submit',
                'value' => 'Go',
                'id' => 'submitbutton',
            ),
        ));

    }
	
	
	 public function addElements()
    {
        // File Input
        $file = new Element\File('file');
        $file
            ->setLabel('Hình ảnh')
            ->setAttributes(array(
                'id' => 'hinhanh',
				'name' => 'hinhanh',
				'required' => 'required',
            ));
        $this->add($file);

        
    }
	public function addElements2()
    {
        // File Input
        $file = new Element\File('file');
        $file
            ->setLabel('Thay đổi hình ảnh')
            ->setAttributes(array(
                'id' => 'hinhanhmoi',
				'name' => 'hinhanhmoi',
				
            ));
        $this->add($file);

        
    }

    public function createInputFilter()
    {
        $inputFilter = new InputFilter\InputFilter();

        // File Input
        $file = new InputFilter\FileInput('hinhanh');
        $file->setRequired(true);
        $file->getFilterChain()->attachByName(
            'filerenameupload',
            array(
                'target'          => 'data',
                'overwrite'       => true,
                'use_upload_name' => true,
            )
        );
        $inputFilter->add($file);

        

        return $inputFilter;
    }
	
	public function setDbAdapter(AdapterInterface $dbAdapter)
    {
        $this->dbAdapter = $dbAdapter;

        return $this;
    }

    public function getDbAdapter()
    {
        return $this->dbAdapter;
    }
}
